package info.yihua.codelab.motan.demo.client;

import info.yihua.codelab.motan.demo.exception.MotanDemoException;
import info.yihua.codelab.motan.demo.service.IMotanDemoService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by Jonathan on 16/7/13.
 */
public class DemoRpcClient {

    public static void main(String[] args) throws InterruptedException {

        ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:motan_demo_client.xml"});

        String[] names = {"motan", "exception"};

        IMotanDemoService service = (IMotanDemoService) ctx.getBean("motanDemoReferer");
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            try {
                System.out.println(service.hello(names[i % 2]) + i);
            } catch (MotanDemoException e) {
                System.out.println(e.getErrCode() + "rpc bussiness exception caught:" + e.getMessage());
            }
            Thread.sleep(1000);
        }
        System.out.println("motan demo is finish.");
        System.exit(0);


    }
}
